#include<iostream>
#include<vector>
using namespace std;

struct ListNode
{
    int val;
    ListNode* next;
    ListNode() : val(0), next(NULL) {}
    ListNode(int x) : val(x), next(NULL) {}
    ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class Solution {
    ListNode* reverse(ListNode* head, ListNode* tail)
    {
        if (!head || !tail) return head;
        ListNode* prev = nullptr, * cur = head, * next = cur->next;
        while (cur != tail)
        {
            cur->next = prev;
            prev = cur;
            cur = next;
            if(cur) next = cur->next;
        }
        head->next = next;
        tail->next = prev;
        return tail;
    }
public:
    ListNode* ZZZ(ListNode* head) {
        int left, right; cin >> left >> right;
        if (left == right) return head;
        ListNode ret(0, head), * prev, * begin, * end;
        prev = begin = end = &ret;
        while (left-- && right--)
        {
            prev = begin;
            begin = begin->next;
            end = end->next;
        }
        while (right--)
            end = end->next;
        prev->next = reverse(begin, end);
        return ret.next;
    }
};
ListNode* createByTail()
{
    ListNode* head;
    ListNode* p1, * p2{};
    int n = 0, num;
    int len;
    cin >> len;
    head = NULL;
    while (n<len && cin >> num)
    {
        p1 = new ListNode(num);
        n = n + 1;
        if (n == 1)
            head = p1;
        else
            p2->next = p1;
        p2 = p1;
    }
    return head;
}
void  displayLink(ListNode* head)
{
    ListNode* p;
    p = head;
    cout << "head-->";
    while (p != NULL)
    {
        cout << p->val << "-->";
        p = p->next;
    }
    cout << "tail\n";
}
int main()
{
    ListNode* head = createByTail();
    head = Solution().ZZZ(head);
    displayLink(head);
    return 0;
}